package com.websocet.controller;

import com.websocet.domain.B;
import com.websocet.domain.SysUser;
import com.websocet.service.SysUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @Author: 陈玉鹏
 * @Description: TODO
 * @DateTime: 2023/1/31 21:34
 */
@RestController
public class TestController {

    private final SysUserService sysUserService;

    public TestController(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    @GetMapping(value = "/list")
    public List<SysUser> getList() {
        return sysUserService.list();
    }

    public static void main(String[] args) {
        List<B> list = new ArrayList<>();
        B a = new B("a", "a");
        B a1 = new B("a1", "a1");
        B a2 = new B("a2", "a2");
        list.add(a);
        list.add(a1);
        list.add(a2);
        List<B> listSum = new ArrayList<>();
        B a22 = new B("a", "a");
        B a23 = new B("a1", "a1");
        B a24 = new B("a2", "a2");
        B a25 = new B("a2", null);
        listSum.add(a22);
        listSum.add(a23);
        listSum.add(a24);
        listSum.add(a25);
        //根据QueryData对象的ruleCode,和version去重
        ArrayList<B> collect = listSum.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(
                                () -> new TreeSet<>(
                                        Comparator.comparing(e -> e.getName() + e.getValue()))), ArrayList::new));
        System.out.println(collect);
    }


}
